//
//  EditStaffInfoCell.m
//  QRMaster
//
//  Created by myApple on 16/4/28.
//  Copyright © 2016年 myApple. All rights reserved.
//

#import "EditStaffInfoCell.h"

@interface EditStaffInfoCell()<UITextFieldDelegate>
{
    UITextField * userNameTextField;
}

@end

@implementation EditStaffInfoCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        //        btnToTimeId = [[NSMutableArray alloc]init];
        [self prepareView];
    }
    return self;
}

-(void)prepareView
{
    float x = 22;
    float y = 2;
    float width = UI_SCREEN_WIDTH - x - 16;
    float height = 40;
    
    userNameTextField = [[UITextField alloc]initWithFrame:CGRectMake(x, y, width, height)];
    userNameTextField.textColor = UIColorFromRGB(0x333333);
    userNameTextField.placeholder = NSLocalizedString(@"input", nil);
    userNameTextField.font = [UIFont systemFontOfSize:16.0];
    userNameTextField.delegate = self;
    [userNameTextField addTarget:self action:@selector(textDidChange:) forControlEvents:UIControlEventEditingChanged];
    [self.contentView addSubview:userNameTextField];
}

//-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
//{
//    BOOL flag = YES;//默认可以点击
//    NSString * newString = [textField.text stringByReplacingCharactersInRange:range withString:string];
//    if ([newString isEqualToString:_userNameString]) {
//        flag = NO;
//    }
//    else
//    {
//        flag = YES;
//    }
//    if (_delegate && [_delegate respondsToSelector:@selector(canSave:userName:)]) {
//        [_delegate canSave:flag userName:newString];
//    }
//    return YES;
//}

-(void)textDidChange:(UITextField *)textField
{
     BOOL flag = YES;//默认可以点击
    if ([textField.text isEqualToString:_userNameString]) {
        flag = NO;
    }
    else
    {
        flag = YES;
    }
    if (_delegate && [_delegate respondsToSelector:@selector(canSave:userName:)]) {
        [_delegate canSave:flag userName:textField.text];
    }

}

-(void)setUserNameString:(NSString *)userNameString
{
    _userNameString = userNameString;
    userNameTextField.text = userNameString;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
